package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.ktwlsoft.archivemanage.domain.dao.entity.UserRoleRelation;
import com.ktwlsoft.archivemanage.domain.dao.repository.IUserRolesMapper;
import com.ktwlsoft.archivemanage.payload.role.EditRoleRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户角色关系
 *
 * @author Name on 2019/10/31 17:14
 * @version 1.0
 */
@Service
public class UserRolesRepositoryService {

    private final IUserRolesMapper iUserRolesMapper;

    public UserRolesRepositoryService(IUserRolesMapper iUserRolesMapper) {
        this.iUserRolesMapper = iUserRolesMapper;
    }

    /**
     * 插入 on 2019-10-24 14:19:41
     * @param userRoleRelation userRoleRelation
     * @return int
     */
    public int insert(UserRoleRelation userRoleRelation){
        return iUserRolesMapper.insert(userRoleRelation);
    }

    /**
     * 更新 on 2019-10-24 14:19:41
     * @param userRoleRelation userRoleRelation
     * @return int
     */
    public int update(UserRoleRelation userRoleRelation){
        return iUserRolesMapper.update(userRoleRelation);
    }

    /**
     * 根据账号id查询 on 2019/10/31 17:33
     *
     * @param accountId accountId
     * @return List<UserRoleRelation>
     */
    public List<UserRoleRelation> getByAccountId(Long accountId){
        return iUserRolesMapper.getByAccountId(accountId);
    }

    /**
     * 根据id集合批量删除信息 on 2019-10-24 14:19:41
     * @param ids ids
     * @return int
     */
    public int deleteByIds(List<Long> ids){
        return iUserRolesMapper.deleteByIds(ids);
    }

    public int updateRoleInfo(EditRoleRequest request) {
        return iUserRolesMapper.updateRoleInfo(request);
    }

    public boolean existsByROleId(Long roleId) {
        return iUserRolesMapper.findByRoleId(roleId).size()>0;
    }
}